clear all
set more off
capture log close
set matsize 11000 

*---- Set Directory ----*
global rootDir = "/Users/AliceZhang/Dropbox/Research_Columbia/Renewables Voting (Urpelainen Zhang)/JOP/UZ_JOP2021_Replication"
global dataDir = "Data"
global resultDir = "Results"
global logDir = "Analysis/logSTATA"
global graphDir = "Results/Figures"

*---- Log File Path ----*
cd "$rootDir/$logDir"
log using 008_robustness_comments, replace


*******************************************************************************
/*				          URPELAINEN & ZHANG 2021	        				 */
*******************************************************************************

/* 

File Name:    	008_robustness_comments.do

By:				Alice Tianbo Zhang (alice.tianbo.zhang@gmail.com)

Last Edited:  	10/11/2021

Purpose:		

Data Used:      votes_wind_panel.dta

Program Used:   - reghdfe -

*/

*******************************************************************************
/*                	   	  	Instrument Stationarity  		  	 		     */
*******************************************************************************

** Load wind votes panel
cd "$rootDir/$dataDir/Final"
use votes_wind_panel.dta, clear

** Create instrument and fixed effects
gen t = year - 2003
gen inter = t * mean_wp

egen stateyear_fixed = group(state year)
egen district_fixed = group(state district)

gen cum_lncapacity_turbine = log(cum_capacity_turbine + 1)
gen cum_lncount_turbine = log(cum_count_turbine +1 )


*------------------- Check for stationarity of instrument --------------------*
// Note: the instrument is a time-invariant variable (mean wind potential) * time trend, so it should be stationary by construction
xtdescribe
xtunitroot ht inter, demean trend //  assume all panels share the same autoregressive parameter and N --> infinity, T is fixed


*******************************************************************************
/*                	   	  			TABLE A21 		  		 			     */
*******************************************************************************

*--------------------- Placebo test in districts w/o wind --------------------* 
use votes_wind_panel.dta, clear
gen t = year - 2003
gen inter = t * mean_wp

egen stateyear_fixed = group(state year)
egen district_fixed = group(state district)

gen cum_lncapacity_turbine = log(cum_capacity_turbine + 1)
gen cum_lncount_turbine = log(cum_count_turbine +1 )

** Check the effect of instrument on environmental voting outcomes for districts with no wind power
reghdfe pro_env inter if cum_capacity_turbine == 0 & raceyear > 2003, absorb(stateyear_fixed district_fixed) vce(cluster district_fixed)
estimates store pro_reduced
reghdfe anti_env inter if cum_capacity_turbine == 0 & raceyear > 2003, absorb(stateyear_fixed district_fixed) vce(cluster district_fixed)
estimates store anti_reduced

** Export LaTeX tables (IV estimates only) 
cd "$rootDir/$resultDir/Tables"
esttab pro_reduced anti_reduced using TableA21.tex, booktabs replace ///
		refcat(cum_capacity_turbine "\emph{Panel: Reduced Form}", nolabel) ///
		b(%9.3f) se noconstant nonotes legend star(* 0.10 ** 0.05 *** 0.01) ///
		varlabels(inter "Mean wind potential * time") varwidth(27) modelwidth(13) ///
		mtitles("Pro-Environment Vote" "Anti-Environment Vote") ///
		stats(N N_clust r2, labels("Observations" "Districts" "\(R^{2}\)") fmt(0 0 2)) ///
		width(\hsize)
		
		
** Close log file
log close
cd "$rootDir/$logDir"
translate 008_robustness_comments.smcl 008_robustness_comments.log, replace

